/**
 * MiniGolf Scorecard
 * Copyright (C) 2010  MiriTheQuiet, http://minigolfscorecard.googlecode.com/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.mtq.mgsc.model;

public class Player {

	public static final byte NUMBER_OF_HOLES = 18;
	public static final byte MAX_STROKES = 7;

	private String name;

	private byte[] holes = new byte[NUMBER_OF_HOLES];

	public Player(String name) {
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public byte getHole(int index) {
		return holes[index];
	}

	public boolean isHoleSet(int index) {
		return getHole(index) > 0;
	}

	public void setHole(int index, byte value) {
		if (value > 0 && value <= MAX_STROKES) {
			holes[index] = value;
		}
	}

	public void addOneToHole(int index) {
		byte val = getHole(index);
		if (val < MAX_STROKES) {
			setHole(index, ++val);
		}
	}

	public byte getSum() {
		byte sum = 0;
		for (byte i = 0; i < holes.length; i++) {
			sum += holes[i];
		}
		return sum;
	}

}
